"""
This is the module for the extensible inline system

An inline system that allows you to register a type of inline that can
be displayed in a block of html. The default parser is XML but it can be 
The inline system uses the XHTML <object> tag to define inlines

Examples:

<inline 
  src="textinline"
  xml:base="news.default">
  <p>This is a text inline</p>
</object>

<object 
  src="photo"
  xml:base="media.photos">
  <param name="id" value="13"/>
</object>

<object 
  src="photogallery"
  xml:base="media.photos">
  <param name="id" value="13"/>
</object>
"""
from django.utils.functional import curry

registry = {}

class AlreadyRegistered(Exception):
    """An inline type with that name has already been registered"""
    pass

class InlineType(object):
    """Simple object to store inline_types"""
    def __init__(self, method, views, **kwargs):
        self.render_html = curry(method, **kwargs)
        for view, view_method in views:
            setattr(view, view_method)

def register(inline_type, render_method, views = {}, **kwargs):
    """
    Registers an inline type with the inline module.
    
    inline_type -- String that must be unique and is what the inlines use to 
        determine how they should be rendered
    
    render_method -- Function that will be called with the kwargs updated by 
        the attributes that are added to the inline object in the text
    
    views -- dictionary that can cantain the different views that can be used 
        to display chooser pages for the object or oembed views for inline 
        editing.
        TODO:determine what these are, what the default values are going to be
    """
    if registry.get(inline_type, None):
        raise AlreadyRegistered(_("An inline type with that name has already "
                                                        "been registered"))
    registry[inline_type] = InlineType(render_method, views, **kwargs)
